home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * FileDlg.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- if (!IS.isModuleInitialized("IS.NOF.DIALOGS.FileDlg"))
- {
-
- /****h* NOF_JavaScript_Library/NOF.DIALOGS.FileDlg
- *
- * NAME
- * NOF.DIALOGS.FileDlg
- *
- * DESCRIPTION
- *
- * The <code>FileDlg</code> class displays a dialog to select a file or files.
- * External dependencies: NOF.App
- ****/
-
- /**
- * constructor
- **/
- function DIALOGS_FileDlg() {
- this.__proto__ = DIALOGS_FileDlg.prototype;
- this.openDialog = null;
- }
- {
- var member = DIALOGS_FileDlg.prototype;
- member.CLASS_NAME = "DIALOGS.FileDlg";
-
- var method = DIALOGS_FileDlg.prototype;
-
- /**
- * Allows the user to select a directory in a dialog.
- *
- * @return the selected directory. If the user cancels the operation the function returns an empty string.
- **/
- method.selectDirectory = function () {
- return NOF.App.getFSIApp().SelectDirectory();
- }
-
- /**
- * Allows the user to select a file in a dialog.
- *
- * @param pLocation specifies the directory to open initially
- * @return the path of the selected file. If the user cancels the operation the function returns an empty string.
- **/
- method.selectFile = function (/*String*/ pLocation) {
- return NOF.App.getFSIApp().SelectFile(pLocation);
- }
-
- /**
- * Allows the user to select multiple files in a dialog.
- * @param pLocation specifies the directory to open initially
- * @param dialogTitle title of the file chooser dialog
- * @param okButtonText
- * @param cancelButtonText
- * @param tipText
- * @param tipValueText
- * @param filters list of file filter objects. A file filter is an object with "text" and "value" members.
- * The value member should contain the list of file names patterns.
- * Example of a filters object:
- * var filters = [ { text: "web images", value: "*.gif;*.jpg;*.jpeg" }, { text: "not web images", value: "*.bmp;*.psd" } ];
- * @return the list (Array) containing the paths of selected files. If the user cancels the operation the function returns null.
- **/
- method.selectFiles = function (/*String*/ pLocation,/*String*/ dialogTitle, /*String*/ okButtonText,/*String*/ cancelButtonText,/*String*/ tipText,/*String*/ tipValueText, /*FileFilter[]*/ filters) {
- this.openDialog = new ActiveXObject(NOF.ProgId.FSIFileOpenDlg);
- var toRet = this.selectMultipleFiles(pLocation, dialogTitle, okButtonText, cancelButtonText, tipText, tipValueText, filters);
- this.openDialog = null;
- return toRet;
- }
-
- /**
- * Allows the user to select multiple images files in a dialog.
- * @param pLocation specifies the directory to open initially
- * @param dialogTitle title of the file chooser dialog
- * @param okButtonText
- * @param cancelButtonText
- * @param tipText
- * @param tipValueText
- * @param filters list of file filter objects. A file filter is an object with "text" and "value" members.
- * The value member should contain the list of file names patterns.
- * Example of a filters object:
- * var filters = [ { text: "web images", value: "*.gif;*.jpg;*.jpeg" }, { text: "not web images", value: "*.bmp;*.psd" }
- * @param useFileNameText label for "Use File Name"
- * @param useFileNameChecked checkbox selection state
- * @return an object with 2 members:
- * fileList - the list (Array) containing the paths of selected file.
- * isChecked - true if the "Use File Name" checkbox was checked, false if not.
- * If the user cancels the operation the function returns null.
- **/
- method.selectImageFiles = function (/*String*/ pLocation,/*String*/ dialogTitle, /*String*/ okButtonText,/*String*/ cancelButtonText,/*String*/ tipText,/*String*/ tipValueText, /*FileFilter[]*/ filters,/*String*/ useFileNameText,/*boolean*/ useFileNameChecked) {
- this.openDialog = new ActiveXObject(NOF.ProgId.FSIImageOpenDlg);
-
- var toRet = null;
-
- if (useFileNameText != null) {
- this.openDialog.SetUseFileNameText(useFileNameText);
- }
- if (typeof(useFileNameChecked) == 'boolean') {
- //alert("useFileNameChecked " + useFileNameChecked);
- this.openDialog.SetUseFileNameChecked( (useFileNameChecked) ? 1 : 0 );
- }
-
- var fileList = this.selectMultipleFiles(pLocation, dialogTitle, okButtonText, cancelButtonText, tipText, tipValueText, filters);
- if (fileList != null) {
-
- toRet = new Object();
- toRet.fileList = fileList;
- toRet.isChecked = (this.openDialog.IsCheckedUseFileName() > 0);
- }
-
- this.openDialog = null;
- return toRet;
- }
-
- /**
- * !this should not be a public method!
- **/
- method.selectMultipleFiles = function (/*String*/ pLocation,/*String*/ dialogTitle, /*String*/ okButtonText,/*String*/ cancelButtonText,/*String*/ tipText,/*String*/ tipValueText, /*FileFilter[]*/ filters) {
- //
- if (this.openDialog == null) {
- return null;
- }
-
- if (pLocation != null) {
- this.openDialog.SetInitialDirectory(pLocation);
- }
-
- if (dialogTitle != null) {
- this.openDialog.SetDialogTitle(dialogTitle);
- }
-
- if (okButtonText != null) {
- this.openDialog.SetOkButtonText(okButtonText);
- }
-
- if (cancelButtonText != null) {
- this.openDialog.SetCancelButtonText(cancelButtonText);
- }
-
- if (tipText != null) {
- this.openDialog.SetTipText(tipText);
- }
-
- if (tipValueText != null) {
- this.openDialog.SetTipValueText(tipValueText);
- }
-
- if (filters != null) {
- for (var i=0; i < filters.length; i++) {
- this.openDialog.AddFilter(filters[i].text, filters[i].value);
- }
- }
-
- if (this.openDialog.Open() == 1) {
-
- var fileList = this.openDialog.GetSelectedFiles();
-
- if (fileList == null) {
- return null;
- }
-
- var toRet = new Array();
-
- for (var i = fileList.lbound( 1 ); i <= fileList.ubound( 1 ); i++ ) {
- toRet[toRet.length] = fileList.getItem( i );
- }
-
- return toRet;
- }
-
- return null;
- }
- }
- DIALOGS.__proto__.FileDlg = DIALOGS_FileDlg;
- }